package com.wgh.product.service.impl;

import com.wgh.product.entity.shop.ProductTag;
import com.wgh.product.mapper.ProductTagMapper;
import com.wgh.product.service.ProductTagService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 商品标签Service实现类
 * 
 * @author AI Shop
 */
@Service
public class ProductTagServiceImpl extends ServiceImpl<ProductTagMapper, ProductTag> implements ProductTagService {

    @Override
    public List<ProductTag> getEnabledTags() {
        return baseMapper.selectEnabledTags();
    }

    @Override
    public ProductTag getTagByName(String name) {
        return baseMapper.selectByName(name);
    }

    @Override
    public int countProductsByTagId(Long tagId) {
        return baseMapper.countProductsByTagId(tagId);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateStatusBatch(List<Long> ids, Integer status) {
        return baseMapper.updateStatusBatch(ids, status) > 0;
    }

    @Override
    public List<ProductTag> searchTags(String keyword) {
        return baseMapper.searchTags(keyword);
    }

    @Override
    public List<ProductTag> getTagPage(Integer pageNum, Integer pageSize) {
        Integer start = (pageNum - 1) * pageSize;
        return baseMapper.selectPage(start, pageSize);
    }
}